home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / aijournl / 1987_01 / aiapp.jan next >
Text File  |  1986-12-21  |  31KB  |  837 lines

  1.  
  2.  
  3.                           AI Apprentice
  4.                 by Bill Thompson and Bev Thompson
  5.              "Creating Expert Systems from Examples"
  6.                      January 1987 AI EXPERT
  7.  
  8.  
  9.  
  10. Figure 1.
  11.  
  12.         batch#      part#       power       symptom      Problem
  13.  
  14.         b           312         ac          no power     powersupply
  15.         a           312         ac          weak         gear bad
  16.         c           412         dc          sparking     powersupply
  17.         d           412         ac          no power     wiring
  18.         c           212         dc          sparking     powersupply
  19.         c           412         ac          weak         wiring
  20.         a           212         ac          no power     gear bad
  21.         b           412         dc          weak         wiring
  22.         b           212         ac          weak         gear bad
  23.  
  24.  
  25.  
  26. Figure 2 - A decision tree produced from the data in Table 1.
  27.  
  28.  
  29.         batch#      part#       power       symptom     Result
  30.  
  31.         b           412         ac          weak         gear bad
  32.         a           212         dc          weak         powersupply
  33.         d           212         dc          sparking     wiring
  34.         d           412         ac          no power     powersupply
  35.  
  36.  
  37.  
  38. Table 1 - A training set of data for a repair problem.
  39.  
  40.     If batch# is a
  41.         then result is gear bad.
  42.  
  43.         If batch# is b
  44.         and part# is 212
  45.         then result is gear bad.
  46.  
  47.         If batch# is b
  48.         and part# is 312
  49.         then result is powersupply.
  50.  
  51.         If batch# is b
  52.         and part# is 412
  53.         then result is wiring.
  54.  
  55.         If batch# is c
  56.         and power is ac
  57.         then result is wiring.
  58.  
  59.         If batch# is c
  60.         and power is dc
  61.         then result is powersupply.
  62.  
  63.         If batch# is d
  64.         then result is wiring.
  65.  
  66.  
  67.  batch# ?
  68.   a:  ---------------------------------------------gear bad
  69.   b:part# ?
  70.      212: ---------------------------------------- gear bad
  71.      312: ---------------------------------------- powersupply
  72.      412: ---------------------------------------- wiring
  73.   c:power??
  74.      ac: ----------------------------------------- wiring
  75.      dc: ----------------------------------------- powersupply
  76.   d: --------------------------------------------- wiring
  77.  
  78.  
  79.  
  80. Table 2 - A new set of data collected for the repair problem.  This data
  81.           is used for validation of the solution.
  82.  
  83.  
  84. clinical    descript      distribution  group         Result
  85.  
  86. fever       upper resp.   epidemic      respiratory   parainfluenza
  87. chills      lower resp.   local         enteric       adenovirus
  88. rash        mid resp.     children      exanthems     mumps
  89. swelling                  hospital      latent        rhinovirus
  90. malaise                   youngadults                 echo
  91. headache                  universal                   coxasackie
  92. cough                                                 varicella
  93.  
  94.  
  95.                                                       rubella
  96.  
  97. Table 3 - Definitions of results and attributes for identifying viruses.
  98.  
  99. level      type of  subject  programming  cover type  basic      Author
  100.            software matter      covered               language
  101. intro/adv  gen/spec gen/spec    no/yes    soft/hard   no/yes
  102. 1.         1.          4.          3.        soft     5.       Jones
  103. 2.         5.          5.          4.        soft     1.       Smith
  104. 1.         1.          1.          3.        soft     1.       Fisher
  105. 1.         1.          1.          3.        hard     5.       Mitchell
  106. 1.         1.          1.          1.        soft     1.       Argyle
  107. 5.         1.          5.          5.        hard     1.       Chang
  108.  
  109.  
  110.  
  111. Table 4 - An example set for selecting a textbook.  This set was produced
  112.           using the Flexigrid program.
  113.  
  114. subject matter ?  (gen/spec)
  115.  < 2.50: programming covered ? (no/yes)
  116.         < 2.00: ---------------------------------- Concepts
  117.         >=2.00: cover ?
  118.                   hard: -------------------------- Today's
  119.                   soft: -------------------------- Information
  120.   >=2.50: level ? (intro/adv)
  121.           < 1.50: -------------------------------- Society
  122.           >=1.50: level ? (intro/adv)
  123.                   < 3.50: ------------------------ Applications
  124.                   >=3.50: ------------------------ Data_structures
  125.  
  126.  
  127. upply of serotinous cones
  128. .
  129.  
  130. prompt 10/acre adequate
  131. Are 10 trees per acre adequate to seed the area ?
  132. .
  133.  
  134. trans 10/acre adequate
  135. 10 per acre is /not/ adequate
  136. .
  137.  
  138. prompt burning planned
  139. Has a prescribed burning been planned ?
  140. .
  141.  
  142. trans burning planned
  143. burning is /not/ planned
  144. .
  145.  
  146. trans use seed tree
  147. You should /not/ use seed trees to seed the area
  148. .
  149.  
  150. 15
  151. if branch 11 is yes
  152. and pine desired is yes
  153. and pine suited is yes
  154. and desirable seed is yes
  155. and serotinous cones is yes
  156. and 10/acre adequate is yes
  157. and burning planned is no
  158. then silviculture method is clearcut
  159. and branch 17 is yes .
  160.  
  161. trans silvaculture method
  162. the best silviculture method to use
  163. .
  164.  
  165. 16
  166. if branch 11 is yes
  167. and pine desired is yes
  168. and pine suited is yes
  169. and desirable seed is yes
  170. and serotinous cones is yes
  171. and 10/acre adequate is no
  172. then silviculture method is clearcut
  173. and branch 17 is yes .
  174.  
  175. 17
  176. if branch 11 is yes
  177. and pine desired is yes
  178. and pine suited is yes
  179. and desirable seed is yes
  180. and serotinous cones is no
  181. and two harvests wanted is yes
  182. and two harvests possible is yes
  183. then silviculture method is shelterwood
  184. and branch 17 is yes .
  185.  
  186. prompt two harvests wanted
  187. Do you want to do two commercial harvests on this area ?
  188. .
  189.  
  190. trans two harvests wanted
  191. two commercial harvests are /not/ wanted
  192. .
  193.  
  194. prompt two harvests possible
  195. Is it possible to get two harvests from this area ?
  196. .
  197.  
  198. trans two harvests possible
  199. two harvests can /not/ be done on this area
  200. .
  201.  
  202. 18
  203. if branch 11 is yes
  204. and pine desired is yes
  205. and pine suited is yes
  206. and desirable seed is yes
  207. and serotinous cones is no
  208. and two harvests wanted is yes
  209. and two harvests possible is no
  210. then silviculture method is clearcut
  211. and branch 17 is yes .
  212.  
  213. 19
  214. if branch 11 is yes
  215. and pine desired is yes
  216. and pine suited is yes
  217. and desirable seed is yes
  218. and serotinous cones is no
  219. and two harvests wanted is no
  220. then silviculture method is clearcut
  221. and branch 17 is yes .
  222.  
  223. 20
  224. if branch 11 is yes
  225. and pine desired is yes
  226. and pine suited is yes
  227. and desirable seed is no
  228. then silviculture method is clearcut
  229. and branch 17 is yes .
  230.  
  231. 21
  232. if branch 11 is yes
  233. and pine desired is yes
  234. and pine suited is no
  235. then convert is yes
  236. and recommend is convert .
  237.  
  238. trans convert
  239. you should /not/ convert the area to some more desirable kind of tree
  240. .
  241.  
  242. 22
  243. if branch 11 is yes
  244. and pine desired is no
  245. then convert is yes
  246. and recommend is convert .
  247.  
  248.  
  249. 26
  250. if branch 17 is yes
  251. and adequate seedbed is yes
  252. then branch 18 is yes .
  253.  
  254. prompt adequate seedbed
  255. Is there an adequate seedbed for planting ?
  256. .
  257.  
  258. trans adequate seedbed
  259. there is /not/ an adequate seedbed for planting
  260. .
  261.  
  262. 27
  263. if branch 17 is yes
  264. and adequate seedbed is no
  265. then prepare site is yes
  266. and branch 18 is yes .
  267.  
  268. trans prepare site
  269. the site should /not/ be prepared before planting
  270. .
  271.  
  272. 28
  273. if branch 18 is yes
  274. and silviculture method is shelterwood
  275. then use natural seeding is yes
  276. and recommend is use natural seeding .
  277.  
  278. trans use natural seeding
  279. natural seeding techniques should /not/ be used
  280. .
  281.  
  282. 29
  283. if branch 18 is yes
  284. and silviculture method is clearcut
  285. and improved stock is yes
  286. then plant is yes
  287. and recommend is plant .
  288.  
  289. prompt improved stock
  290. Is there improved planting stock available ?
  291. .
  292.  
  293. trans improved stock
  294. there is /not/ improved stock available
  295. .
  296.  
  297. trans plant
  298. since there is better stock available you can /not/ plant using that stock
  299. .
  300.  
  301. 30
  302. if branch 18 is yes
  303. and silviculture method is clearcut
  304. and improved stock is no
  305. and good cone supply is yes
  306. then scatter cones is yes
  307. and recommend is scatter cones .
  308.  
  309. prompt good cone supply
  310. Is there a good supply of serotinous cones on the area ?
  311. .
  312.  
  313. trans good cone supply
  314. there is /not/ a good cone supply
  315. .
  316.  
  317. trans scatter cones
  318. you should /not/ scatter the supply of serotinous cones over the area
  319. .
  320.  
  321. 31
  322. if branch 18 is yes
  323. and silviculture method is clearcut
  324. and improved stock is no
  325. and good cone supply is no
  326. then direct seed is yes
  327. and recommend is direct seed .
  328.  
  329. trans direct seed
  330. Since the cone supply is inadequate, you should /not/ directly seed the
  331. area
  332. .
  333.  
  334.  
  335. -------------------------------------------------------------------------
  336.  
  337. The following comments are not a part of the knowledge base.  If you
  338. try to run the knowledge base this part of the file should be removed
  339.  
  340.  
  341. Abbreviated KEY
  342.  
  343. 1.  stocking good is yes ............................. 2
  344. 1.  stocking good is no  ............................. 10
  345.     2. avg < 5 is yes ................................ 3
  346.     2. avg < 5 is no ................................. 4
  347. 3.  2000 + per acre is yes ..........WEED OR CLEAN.... 8
  348. 3.  2000 + per acre is no ............................ 8
  349.     4. age is mature ................................. 11
  350.     4. age is immature ............................... 5
  351. 5.  site index > 60 is yes ........................... 6
  352. 5.  site index > 60 is no ............................ 9
  353.     6. product size is large ......................... 7
  354.     6. product size is small ......................... 9
  355. 7.  120 + basal area is yes .........THIN............. 9
  356. 7.  120 + basal area is no ........................... 9
  357.     8. severe competition is yes ....RELEASE.......... 9
  358.     8. severe competition is no ...................... 9
  359. 9.  high risk is yes ................................. CONTROL IF FEASIBLE
  360. 9.  high risk is no .................................. WAIT
  361.     10. other resources is yes ....................... MAINTAIN
  362.     10. other resources is no ........................ 11
  363. 11. pine suitable is yes ............................. 12
  364. 11. pine suitable is no .............................. CONVERT
  365.     12. desirable seed is yes ........................ 13
  366.     12. desirable seed is no ........USE CLEARCUT..... 17
  367. 13. serotinous cones is yes .......................... 14
  368. 13. serotinous cones is no ........................... 16
  369.     14. 10/acre adequate is yes ...................... 15
  370.     14. 10/acre adequate is no ......USE CLEARCUT..... 17
  371. 15. burning planned is yes ........................... USE SEED TREE
  372. 15. burning planned is no ...........USE CLEARCUT..... 17
  373.     16. two harvests wanted is yes ..USE SHELTERWOOD.. 17
  374.     16. two harvests wanted is no ...USE CLEARCUT..... 17
  375. 17. adequate seedbeds is yes ......................... 18
  376. 17. adequate seedbeds is no .........PREPARE SITE..... 18
  377.     18. silviculture method is shelterwood ........... USE NATURAL SEEDING
  378.     18. silviculture method is clearcut .............. 19
  379. 19. improved stock is yes ............................ PLANT
  380. 19. improved stock is no ............................. 20
  381.     20. good cone supply is yes ...................... SCATTER CONES
  382.     20. good cone supply is no ....................... DIRECT SEED
  383.  
  384.  
  385.  
  386. The purpose of this exercise is to show how a knowledge base can be
  387. designed to directly follow a key.  There are several places where the
  388. KB could have been made more efficient, but this would have meant
  389. departing from the order of the key.  You might find it an interesting
  390. exercise to explore other ways this same information could have been
  391. represented in the KB.
  392.  
  393. The key appears in the Managers Handbood for Jack Pine in the North Central
  394. States.  The Handbook was produced by the North Central Forest Experiment
  395. Station of the Forest Service of the U.S. Dept. of Agriculture.  Our
  396. intention in writing this knowledge base is to show the structure of a
  397. knowledge base written for a backward chaining inference engine directly
  398. from an existing document.  If this KB were to be actually used, it would
  399. need to have clearer questions and more explanations to the user.  These
  400. explanations are provided in the handbook and could be easily incorporated
  401. into the knowledge base.
  402.  
  403. The knowledge base will run on the expert system shell MicroExpert which is
  404. an example of a backward chaining inference engine. MicroExpert is
  405. available from McGraw-Hill for $49.95 and can be ordered by calling 1-800-
  406. 628-0004 or, in NY, 212-512-2999 . The knowledge base is described in the
  407. column AI Apprentice which appears in the November issue of AI Expert
  408. magazine.  The design details of the inference engine which runs the KB is
  409. described in the article "Inside an Expert System" in the April 1985
  410. isuue of BYTE magazine.
  411.  
  412. MicroExpert, AI Apprentice and "Inside an Expert System" are all written
  413. by Bev and Bill Thompson . We're always happy to hear about your thoughts
  414. and comments, good or bad on any of our work.  Contact us at the address
  415. below, on Compuserve or BIX. Our Compuserve id is 76703,4324 and we can be
  416. reached by Easyplex or in the AI Expert Forum.  Our BIX id is bbt and  we
  417. may  be  contacted via BIXmail or by leaving comments in the  MicroExpert
  418. conference.
  419.  
  420. Bill and Bev Thompson
  421. R.D. 2 Box 430
  422. Nassau, N.Y.  12123
  423.  
  424.  
  425.                             TREES.PRO
  426.                          PROLOG program 
  427.  
  428.  
  429. /* This PDPROLOG program implements a knowledge base based upon the
  430.    following key:
  431.  
  432.    To run the program type "go."
  433.    Caution - This program can be very S L O W.
  434.  
  435. Abbreviated KEY
  436.  
  437. 1.  stocking good is yes ............................. 2
  438. 1.  stocking good is no  ............................. 10
  439.     2. avg < 5 is yes ................................ 3
  440.     2. avg < 5 is no ................................. 4
  441. 3.  2000 + per acre is yes ..........WEED OR CLEAN.... 8
  442. 3.  2000 + per acre is no ............................ 8
  443.     4. age is mature ................................. 11
  444.     4. age is immature ............................... 5
  445. 5.  site index > 60 is yes ........................... 6
  446. 5.  site index > 60 is no ............................ 9
  447.     6. product size is large ......................... 7
  448.     6. product size is small ......................... 9
  449. 7.  120 + basal area is yes .........THIN............. 9
  450. 7.  120 + basal area is no ........................... 9
  451.     8. severe competition is yes ....RELEASE.......... 9
  452.     8. severe competition is no ...................... 9
  453. 9.  high risk is yes ................................. CONTROL IF FEASIBLE
  454. 9.  high risk is no .................................. WAIT
  455.     10. other resources is yes ....................... MAINTAIN
  456.     10. other resources is no ........................ 11
  457. 11. pine suitable is yes ............................. 12
  458. 11. pine suitable is no .............................. CONVERT
  459.     12. desirable seed is yes ........................ 13
  460.     12. desirable seed is no ........USE CLEARCUT..... 17
  461. 13. serotinous cones is yes .......................... 14
  462. 13. serotinous cones is no ........................... 16
  463.     14. 10/acre adequate is yes ...................... 15
  464.     14. 10/acre adequate is no ......USE CLEARCUT..... 17
  465. 15. burning planned is yes ........................... USE SEED TREE
  466. 15. burning planned is no ...........USE CLEARCUT..... 17
  467.     16. two harvests wanted is yes ..USE SHELTERWOOD.. 17
  468.     16. two harvests wanted is no ...USE CLEARCUT..... 17
  469. 17. adequate seedbeds is yes ......................... 18
  470. 17. adequate seedbeds is no .........PREPARE SITE..... 18
  471.     18. silviculture method is shelterwood ........... USE NATURAL SEEDING
  472.     18. silviculture method is clearcut .............. 19
  473. 19. improved stock is yes ............................ PLANT
  474. 19. improved stock is no ............................. 20
  475.     20. good cone supply is yes ...................... SCATTER CONES
  476.     20. good cone supply is no ....................... DIRECT SEED
  477.  
  478.  
  479.  
  480. The purpose of this exercise is to show how an expert system can be
  481. designed to directly follow a key.  There are several places where the
  482. program could have been made more efficient, but this would have meant
  483. departing from the order of the key.  You might find it an interesting
  484. exercise to explore other ways this same information could have been
  485. represented in the program.
  486.  
  487. The key appears in the Managers Handbood for Jack Pine in the North Central
  488. States.  The Handbook was produced by the North Central Forest Experiment
  489. Station of the Forest Service of the U.S. Dept. of Agriculture.  Our
  490. intention in writing this knowledge base is to show the structure of a
  491. knowledge base written for a backward chaining inference engine directly
  492. from an existing document.  If this KB were to be actually used, it would
  493. need to have clearer questions and more explanations to the user.  These
  494. explanations are provided in the handbook and could be easily incorporated
  495. into the knowledge base.
  496.  
  497. This program is similar to the KB for the expert system shell
  498. MicroExpert which is an example of a backward chaining inference engine.
  499. MicroExpert is available from McGraw-Hill for $49.95 and can be ordered
  500. by calling 1-800-628-0004 or, in NY, 212-512-2999 .
  501. The knowledge base is described in the AI Apprentice column which appears
  502. in the November issue of AI Expert magazine.
  503. The design details of the inference engine which runs the KB is
  504. described in the article "Inside an Expert System" in the April 1985
  505. isuue of BYTE magazine.
  506.  
  507. MicroExpert, AI Apprentice and "Inside an Expert System" are all written
  508. by Bev and Bill Thompson . We're always happy to hear about your thoughts
  509. and comments, good or bad on any of our work.  Contact us at the address
  510. below, on Compuserve or BIX. Our Compuserve id is 76703,4324 and we can be
  511. reached by Easyplex or in the AI Expert Forum.  Our BIX id is bbt and  we
  512. may  be  contacted via BIXmail or by leaving comments in the  MicroExpert
  513. conference.
  514.  
  515. Bill and Bev Thompson
  516. R.D. 2 Box 430
  517. Nassau, N.Y.  12123      */
  518.  
  519. /* Control - In MicroExpert terms, the goal of the consultation is
  520.    recommendation */
  521.  
  522. go :- clear_kb,
  523.       give_advice.
  524. give_advice :- recommendation(X),
  525.                fail.
  526. give_advice :- print_advice.
  527.  
  528. /* The rules -
  529.    These are implemented this way to mimic the MicroExpert rule set.
  530.    Looking at them side by side should show the similarities. */
  531.  
  532. fact(branch8,yes) :- fact('stocking good',yes),
  533.                      fact('avg < 5',yes),
  534.                      fact('2000+ per acre',yes),
  535.                      recommend('The stand of jack pine must be weeded and cleaned.').
  536. fact(branch8,yes) :- fact('stocking good',yes),
  537.                      fact('avg < 5',yes),
  538.                      fact('2000+ per acre',no).
  539. fact(branch9,no) :- fact('stocking good',yes),
  540.                     fact('avg < 5',no),
  541.                     fact(age,mature),
  542.                     assertz(fact(branch11,yes)).
  543. fact(branch11,yes) :- fact('stocking good',yes),
  544.                       fact('avg < 5',no),
  545.                       fact(age,mature),
  546.                       assertz(fact(branch9,no)).
  547. fact(branch9,yes) :- fact('stocking good',yes),
  548.                      fact('avg < 5',no),
  549.                      fact(age,immature),
  550.                      fact('site index > 60',yes),
  551.                      fact('product size',large),
  552.                      fact('120+ basal area',yes),
  553.                      recommend('It is important to thin the area').
  554. fact(branch9,yes) :- fact('stocking good',yes),
  555.                      fact('avg < 5',no),
  556.                      fact(age,immature),
  557.                      fact('site index > 60',yes),
  558.                      fact('product size',large),
  559.                      fact('120+ basal area',no).
  560. fact(branch9,yes) :- fact('stocking good',yes),
  561.                      fact('avg < 5',no),
  562.                      fact(age,immature),
  563.                      fact('site index > 60',yes),
  564.                      fact('product size',large).
  565. fact(branch9,yes) :- fact('stocking good',yes),
  566.                      fact('avg < 5',no),
  567.                      fact(age,immature),
  568.                      fact('site index > 60',yes).
  569. recommendation(maintain) :-
  570.        fact('stocking good',no),
  571.        fact('other resources',yes),
  572.        recommend('You should maintain the stand in its present condition').
  573. fact(branch11,yes) :- fact('stocking good',no),
  574.                       fact('other resources',no).
  575. fact(branch9,yes) :- fact(branch8,yes),
  576.                      fact('severe competition',yes),
  577.                      recommend('Competing trees should be eliminated.').
  578. fact(branch9,yes) :- fact(branch8,yes),
  579.                      fact('severe competition',no).
  580. recommendation(control) :-
  581.         fact(branch9,yes),
  582.         fact('high risk',yes),
  583.         recommend('The current area should be controlled, if at all feasible.').
  584. recommendation(wait) :-
  585.         fact(branch9,yes),
  586.         fact('high risk',no),
  587.         recommend('You should wait before doing anything else to this stand.').
  588. recommendation('use seed tree') :-
  589.         fact(branch11,yes),
  590.         fact('pine desired',yes),
  591.         fact('pine suited',yes),
  592.         fact('desirable seed',yes),
  593.         fact('serotinous cones',yes),
  594.         fact('10/acres adequate',yes),
  595.         fact('burning planned',yes),
  596.         recommend('You should use seed trees to seed the area.').
  597. fact(branch17,yes) :-
  598.             fact(branch11,yes),
  599.             fact('pine desired',yes),
  600.             fact('pine suited',yes),
  601.             fact('desirable seed',yes),
  602.             fact('serotinous cones',yes),
  603.             fact('10/acres adequate',yes),
  604.             fact('burning planned',no),
  605.             add_fact(silvaculture,clearcut),
  606.             recommend('The best silvaculture method to use is clearcut.').
  607. fact(branch17,yes) :-
  608.         fact(branch11,yes),
  609.         fact('pine desired',yes),
  610.         fact('pine suited',yes),
  611.         fact('desirable seed',yes),
  612.         fact('serotinous cones',yes),
  613.         fact('10/acres adequate',no),
  614.         add_fact(silvaculture,clearcut),
  615.         recommend('The best silvaculture method to use is clearcut.').
  616. fact(branch17,yes) :-
  617.         fact(branch11,yes),
  618.         fact('pine desired',yes),
  619.         fact('pine suited',yes),
  620.         fact('desirable seed',yes),
  621.         fact('serotinous cones',no),
  622.         fact('two harvests wanted',yes),
  623.         fact('two harvests possible',yes),
  624.         add_fact(silvaculture,shelterwood),
  625.         recommend('The best silvaculture method to use is the shlterwood method.').
  626. fact(branch17,yes) :-
  627.         fact(branch11,yes),
  628.         fact('pine desired',yes),
  629.         fact('pine suited',yes),
  630.         fact('desirable seed',yes),
  631.         fact('serotinous cones',no),
  632.         fact('two harvests wanted',yes),
  633.         fact('two harvests possible',no),
  634.         add_fact(silvaculture,clearcut),
  635.         recommend('The best silvaculture method to use is clearcut.').
  636. fact(branch17,yes) :-
  637.         fact(branch11,yes),
  638.         fact('pine desired',yes),
  639.         fact('pine suited',yes),
  640.         fact('desirable seed',yes),
  641.         fact('serotinous cones',no),
  642.         fact('two harvests wanted',no),
  643.         add_fact(silvaculture,clearcut),
  644.         recommend('The best silvaculture method to use is clearcut.').
  645. fact(branch17,yes) :-
  646.         fact(branch11,yes),
  647.         fact('pine desired',yes),
  648.         fact('pine suited',yes),
  649.         fact('desirable seed',no),
  650.         add_fact(silvaculture,clearcut),
  651.         recommend('The best silvaculture method to use is clearcut.').
  652. recommendation(convert) :-
  653.         fact(branch11,yes),
  654.         fact('pine desired',yes),
  655.         fact('pine suited',no),
  656.         recommend('You should convert the area to some more desirable kind of tree.').
  657. recommendation(convert) :-
  658.         fact(branch11,yes),
  659.         fact('pine desired',no),
  660.         recommend('You should convert the area to some more desirable kind of tree.').
  661. fact(branch18,yes) :-
  662.         fact(branch17,yes),
  663.         fact('adequate seedbed',yes).
  664. fact(branch18,yes) :-
  665.         fact(branch17,yes),
  666.         fact('adequate seedbed',no),
  667.         recommend('The site should be prepared before planting.').
  668. recommendation('natural seeding') :-
  669.         fact(branch18,yes),
  670.         fact(silvaculture,shelterwood),
  671.         recommend('The natural seeding technique should be used.').
  672. recommendation(plant) :-
  673.         fact(branch18,yes),
  674.         fact(silvaculture,clearcut),
  675.         fact('improved stock',yes),
  676.         recommend('Since there is better stock available, you can plant using that stock.').
  677. recommendation('scatter cones') :-
  678.         fact(branch18,yes),
  679.         fact(silvaculture,clearcut),
  680.         fact('improved stock',no),
  681.         fact('good cone supply',yes),
  682.         recommend('You should scatter the serotinous cones over the area.').
  683. recommendation('direct seed') :-
  684.         fact(branch18,yes),
  685.         fact(silvaculture,clearcut),
  686.         fact('improved stock',no),
  687.         fact('good cone supply',no),
  688.         recommend('You should directly seed the area.').
  689.  
  690. /* These routines add new facts to the internal knowledge base - kb */
  691.  
  692. fact(X,Y) :- kb(X,Y),! .
  693. fact(X,Y) :- not(kb(X,Anything)),
  694.              question(X,Answer),
  695.              assertz(kb(X,Answer)),
  696.              Y = Answer.
  697.  
  698. add_fact(X,Y) :- kb(X,Y),!.
  699. add_fact(X,Y) :- assertz(kb(X,Y)).
  700.  
  701. recommend(X) :- add_fact(advice,X).
  702.  
  703. /* Questions to ask the user */
  704.  
  705. question('stocking good',Ans) :-
  706.         print('Is the stocking of the jack pine stand currently'),nl,
  707.         print('at least minimum ? '),nl,nl,
  708.         print('If you are unsure of how to determine stocking,'),nl,
  709.         print('see page 4 in the Managers Handbook for Jack Pine'),
  710.         nl,
  711.         ask('',Ans,[ yes , no ]).
  712. question('avg < 5',Ans) :-
  713.         ask('Is the average diameter of the trees less than 5 inches ?',
  714.              Ans,[yes,no]).
  715. question('2000+ per acre',Ans) :-
  716.         ask('Are there 2000 or more trees per acre ?',Ans,[yes,no]).
  717. question(age,Ans) :-
  718.         ask('Is the age of the stand mature or immature ?',
  719.              Ans,[mature,immature]).
  720. question('site index > 60',Ans) :-
  721.         ask('Is the site index greater than 60 ?',Ans,[yes,no]).
  722. question('product size',Ans) :-
  723.         ask('Do you want to manage the timber for large or small products ?',
  724.             Ans,[large,small]).
  725. question('120+ basal area',Ans) :-
  726.         ask('Is the basal area per acre at least 120 square feet ?',
  727.             Ans,[yes,no]).
  728. question('other resources',Ans) :-
  729.         ask('Do you want to maintain this condition to support other resources?',
  730.              Ans,[yes,no]).
  731. question('severe competition',Ans) :-
  732.         ask('Is there severe overstory competition ?',Ans,[yes,no]).
  733. question('high risk',Ans) :-
  734.         ask('Is there a high risk of loss or injury ?',Ans,[yes,no]).
  735. question('pine desired',Ans) :-
  736.         ask('Do you want to keep jack pine in this area ?',Ans,[yes,no]).
  737. question('pine suited',Ans) :-
  738.         ask('Is jack pine well suited to this site ?',Ans,[yes,no]).
  739. question('desirable seed',Ans) :-
  740.         ask('Is there a desirable jack pine seed source on the area ?',
  741.              Ans,[yes,no]).
  742. question('serotinous cones',Ans) :-
  743.         ask('Do the trees on the site have serotinous cones ?',Ans,[yes,no]).
  744. question('10/acres adequate',Ans) :-
  745.         ask('Are 10 trees per acre adequate to seed the area ?',Ans,[yes,no]).
  746. question('burning planned',Ans) :-
  747.         ask('Has a prescribed burning been planned ?',Ans,[yes,no]).
  748. question('two harvests wanted',Ans) :-
  749.         ask('Do you want two commercial harvests on this area ?',Ans,[yes,no]).
  750. question('two harvests possible',Ans) :-
  751.         ask('Is it possible to get two harvests from this area ?',Ans,[yes,no]).
  752. question('adequate seedbed',Ans) :-
  753.         ask('Is there an adequate seedbed for planting ?',Ans,[yes,no]).
  754. question('improved stock',Ans) :-
  755.         ask('Is there an improved planting stock available ?',Ans,[yes,no]).
  756. question('good cone supply',Ans) :-
  757.         ask('Is there a good supply of serotinous cones in the area ?',
  758.              Ans,[yes,no]).
  759.  
  760. /* Utility Routines - to be useful, we should add some routines to allow
  761.                        the user to ask "How" and "Why" */
  762.  
  763. display_kb :- kb(X,Y),
  764.               print(X,' is ',Y),
  765.               nl,
  766.               fail.
  767. display_kb.
  768.  
  769.  
  770. print_advice :-
  771.     nl,nl,
  772.     print('Based upon your responses, the following is recommended :'),nl,nl,
  773.     show_advice.
  774. show_advice :-
  775.     kb(advice,X),
  776.     print(X),
  777.     nl,
  778.     fail.
  779. show_advice :-
  780.     nl,print('To see the complete set of derived facts,'),
  781.     print('type "display_kb."').
  782.  
  783.  
  784. clear_kb :- retract(kb(_,_)),
  785.             fail .
  786. clear_kb.
  787.  
  788. member(X,[X|_]).
  789. member(X,[_|Y]) :- member(X,Y).
  790.  
  791. ask(Ques,Ans,LegalResponses) :-
  792.     nl,print(Ques,' '),
  793.     read(Ans),
  794.     member(Ans,LegalResponses),!.
  795. ask(Ques,Ans,LegalResponses) :-
  796.    nl,nl,nl,
  797.    print('Please respond with : ',LegalResponses),nl,nl,
  798.    ask(Ques,Ans,LegalResponses).
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.                       Listings and Figures
  807.                   printed in AI EXPERT magazine
  808.  
  809.  
  810. 1.  Jack pine stand with minimum or higher stocking .................. 2
  811. 1.  Jack pine stand with less than minimum stocking .................. 10
  812.  
  813.     2.  Average tree diameter less than 5 inches ..................... 3
  814.     2.  Average tree diameter 5 inches or more ....................... 4
  815.  
  816. 3.  2,000 or more trees per acre ..................WEED OR CLEAN ..... 8
  817. 3.  Less than 2,000 trees per acre ................................... 8
  818.  
  819.     4.  Stand is mature .............................................. 11
  820.     4.  Stand is not mature .......................................... 5
  821.  
  822. Figure 1 - Key for forest management taken from USDA Forest Service
  823.            Handbook
  824.  
  825.  
  826.  
  827.  
  828.                                                         |-- yes ===> weed or clean
  829.                                                         |            and do # 8
  830.                              |-- yes --- 2000+ per acre-|
  831.                              |                          |-- no ===> do # 8
  832.          |-- yes -- diameter-|
  833.          |          < 5 in.  |             |-- mature ===> do # 11
  834. minimum  |                   |-- no -- age-|
  835. stocking-|                                 |-- young ===> do # 5
  836.          |
  837.          |